package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.PurchaseChannel;
import com.zoo.diannaopeijian.mapper.PurchaseChannelMapper;
import com.zoo.diannaopeijian.service.PurchaseChannelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 进货渠道服务实现类
 */
@Service
public class PurchaseChannelServiceImpl implements PurchaseChannelService {
    @Resource
    private PurchaseChannelMapper purchaseChannelMapper;

    @Override
    public boolean addPurchaseChannel(PurchaseChannel purchaseChannel) {
        if (CheckUtil.allNullBeanCheck(purchaseChannel)) {
            return true;
        }
        return purchaseChannelMapper.insertSelective(purchaseChannel) == 1;
    }

    @Override
    public boolean deletePurchaseChannelById(Integer purchaseChannelId) {
        if (purchaseChannelId == null) {
            throw new NullPointerException();
        }
        return purchaseChannelMapper.deleteByPrimaryKey(purchaseChannelId) == 1;
    }

    @Override
    public boolean updatePurchaseChannel(PurchaseChannel purchaseChannel) {
        if (CheckUtil.allNullBeanCheck(purchaseChannel)) {
            return true;
        }
        return purchaseChannelMapper.updateByPrimaryKeySelective(purchaseChannel) == 1;
    }

    @Override
    public List<PurchaseChannel> getAllPurchaseChannel() {
        return purchaseChannelMapper.select(null);
    }
}
